* Importing packages
* ssc install estout
* ssc install ftools
* ssc install reghdfe
* ssc install cibar
* ssc install rev
* ssc install sutex
* ssc install cibar
* ssc install ipfweight
* ssc install ciplot

**************************************************************************************************
************************************************* CPS_replication  *******************************
**************************************************************************************************

cd "[insert your directory]"
global PathTab "[insert your directory]"

* To replicate the below results, please download "WVS_Cross-National_Wave_7_stata_v6_0.dta" and "ZA7500_v5-0-0.dta" data files from public repositories, as indicated in READ_ME.txt

*Table S3
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
tab Edu
*WVS data:
clear all
use "WVS_Cross-National_Wave_7_stata_v6_0.dta" 
*Education:
tab Q275 if B_COUNTRY_ALPHA=="DEU"


*Table S4
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
tab Employment	
*WVS data:
clear all
use "WVS_Cross-National_Wave_7_stata_v6_0.dta" 
*Employment:
tab Q279 if B_COUNTRY_ALPHA=="DEU"


*Table S5
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
tab Party
*Dimap data: Manually transferred into the table from the link in the notes-section of the table. 

*Table S26
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
gen Leftwing=0
replace Leftwing=1 if Party=="Bündnis90/Grüne" | Party=="SPD" 
gen Collegeedu=0
replace Collegeedu=1 if education=="Bachelor" | education=="Master" | education=="PhD"
label variable age "Age"
label variable FemaleSub "Female"
label variable Collegeedu "College-educated"
eststo: reg PC FemaleSub, r
eststo: reg PC age, r
eststo: reg PC Collegeedu, r
eststo: reg PC Leftwing, r
esttab using "${PathTab}TableS26.tex", p star(* 0.1 ** 0.05 *** 0.01)  r2 label replace mgroups("Dependent variable: Political Correctness", pattern(1 0 0 0 ) span prefix(\multicolumn{@span}{c}{)suffix(}) ) collabels(none) eqlabels(none) nomtitle
est clear

*Table S27
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
label define Genderlabel 0 "Male" 1 "Female" 
label values FemaleSub Genderlabel 
estpost tabstat PC_1 PC_2, by(FemaleSub) statistics(mean sd) columns(statistics) listwise
esttab using "${PathTab}TableS27.tex", main(mean) aux(sd) nostar unstack noobs nonote nomtitle nonumber replace
est clear

*Table S28
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
gen age_group = .
replace age_group = 1 if age <= 20
replace age_group = 2 if age > 20 & age <= 30
replace age_group = 3 if age > 30 & age <= 40
replace age_group = 4 if age > 40 & age <= 50
replace age_group = 5 if age > 50 & age <= 60
replace age_group = 6 if age > 60
label define agegrp 1 "0-20" 2 "21-30" 3 "31-40" 4 "41-50" 5 "51-60" 6 "61+"
label values age_group agegrp
estpost tabstat PC_1 PC_2, by(age_group) statistics(mean sd) columns(statistics) listwise
esttab using "${PathTab}TableS28.tex", main(mean) aux(sd) nostar unstack noobs nonote nomtitle nonumber replace
est clear


*Table S29
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
encode education, gen(edu)
estpost tabstat PC_1 PC_2, by(edu) statistics(mean sd) columns(statistics) listwise
esttab using "${PathTab}TableS29.tex", main(mean) aux(sd) nostar unstack noobs nonote nomtitle nonumber replace
est clear


*Table S30
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"
encode party, gen(partypref)
estpost tabstat PC_1 PC_2, by(partypref) statistics(mean sd) columns(statistics) listwise
esttab using "${PathTab}TableS30.tex", main(mean) aux(sd) nostar unstack noobs nonote nomtitle nonumber replace
est clear
	
	
*Table S39
*Our data (Germany stage 3): 
clear all
use "DE_stage3.dta"		
eststo: reg closeness Immigrant if Party=="Bündnis90/Grüne", r
eststo: reg closeness Immigrant if Party=="CDU/CSU", r
eststo: reg closeness Immigrant if Party=="SPD", r 
eststo: reg closeness Immigrant if Party=="Die Linke", r
eststo: reg closeness Immigrant if Party=="FDP", r
eststo: reg closeness Immigrant if Party=="AfD", r
esttab using "${PathTab}TableS39.tex", p star(* 0.1 ** 0.05 *** 0.01)  stats(N r2 r2_a) replace 
est clear


*Table S44
clear all
use "WVS_Cross-National_Wave_7_stata_v6_0.dta" 
tab Q33_3 if B_COUNTRY_ALPHA=="DEU"
tab Q33_3 if B_COUNTRY_ALPHA=="GRC"
use "ZA7500_v5-0-0.dta" 
tab v81 if c_abrv=="PL"


*Table S45
clear all
use "WVS_Cross-National_Wave_7_stata_v6_0.dta" 
tab Q40 if B_COUNTRY_ALPHA=="DEU"
tab Q40 if B_COUNTRY_ALPHA=="GRC"
use "ZA7500_v5-0-0.dta" 
tab v49 if c_abrv=="PL"




